package com.ncwu.order.service.impl;

import com.ncwu.order.bean.Order;
import com.ncwu.order.feign.ProductFeignClient;
import com.ncwu.order.service.OrderService;
import com.ncwu.product.bean.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Arrays;


@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private ProductFeignClient productFeignClient;

    @Override
    public Order getOrder(Long productId, Long userId) {
        //使用feign调用商品服务
        Product product = productFeignClient.getProductById(productId);

        Order order = new Order();
        // 这里模拟从数据库中查询到的订单数据
        order.setId(1L);
        order.setAddress("尚硅谷");
        order.setUserId(userId);
        order.setNickName("zhangsan");
        order.setTotalAmount(product.getPrize().multiply(new BigDecimal(product.getCount())));
        order.setProductList(Arrays.asList(product));
        return order;
    }
}
